import axios from 'axios'
import qs from 'qs'
const request = axios.create({
    baseURL: "http://localhost:1111/",
    timout: 5000
})
// http request 拦截器
request.interceptors.request.use(config => {
    /* 区分post/get请求 */
    config.method == 'post' ? config.data = qs.stringify({ ...config.data }) : config.params = { ...config.params };
    config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
    return config;
},
    err => {
        return Promise.reject(err)
    }
)
// http response 拦截器
request.interceptors.response.use(
    response => {/* 接口成功 */
        // console.log(response.data)
      return response
    },
    //接口错误状态处理，也就是说无响应时的处理
    error => {
      return Promise.reject(error) 
    })
export default request;